#include "..\\Includes\\StateManager.h"



//constructor
StateManager::StateManager()
{
	//init the different states to their default settings
	m_nMenuState = MenuStates::eMenu_Main;
	


}


MenuState StateManager::GetMenuState()
{
	return m_nMenuState;
}


bool StateManager::ChangeMenuState(MenuState nState)
{
	//Check to see if the change is valid first
	if(nState == MenuStates::eMenu_Game)
	{
		//we can't go from anything but pause or main to the game menu state
		if(m_nMenuState == MenuStates::eMenu_Highscore 
			|| m_nMenuState == MenuStates::eMenu_Settings
			|| m_nMenuState == MenuStates::eMenu_Game)
		{
			MikeUtils::ASSERT(false, "Invalid game state changes!", __FILE__, __LINE__);
			return false;
		}
		else
		{
			m_nMenuState = nState;
			return true;
		}
	}
	else if(nState == MenuStates::eMenu_Pause)
	{
		if(m_nMenuState == MenuStates::eMenu_Highscore)
		{
			MikeUtils::ASSERT(false, "Invalid game state changes!", __FILE__, __LINE__);
			return false;
		}
		else
		{
			m_nMenuState = nState;
			return true;
		}
	}
	else if(nState == MenuStates::eMenu_Highscore)
	{
		if(m_nMenuState != MenuStates::eMenu_Main)
		{
			MikeUtils::ASSERT(false, "Invalid game state changes!", __FILE__, __LINE__);
			return false;
		}
		else
		{
			m_nMenuState = nState;
			return true;
		}

	}
	else if(nState == MenuStates::eMenu_Settings)
	{

		if(m_nMenuState != MenuStates::eMenu_Pause || m_nMenuState != MenuStates::eMenu_Main)
		{
			MikeUtils::ASSERT(false, "Invalid game state changes!", __FILE__, __LINE__);
			return false;
		}
		else
		{
			m_nMenuState = nState;
			return true;
		}
	}


	m_nMenuState = nState;
	return true;




}


//Tries to change the menu state, wherever it is currently at.
//returns the new MenuState
MenuState StateManager::RequestMenuStateChange(CMenu * pMenu)
{

	//if we request a state change at the main menu,
	//then we are saying that the user pressed enter on
	//whatever element they had selected.
	if(m_nMenuState == MenuStates::eMenu_Main)
	{
		if(pMenu->CurrentItemSelected() == MenuItems::eMenuItem_Start)
		{
			ChangeMenuState(MenuStates::eMenu_Game); //start the game! Woot!
			pMenu->Disable();

		}
		else if(pMenu->CurrentItemSelected() == MenuItems::eMenuItem_Settings)
		{


		}
		else if(pMenu->CurrentItemSelected() == MenuItems::eMenuItem_HowTo)
		{

		}
		else if(pMenu->CurrentItemSelected() == MenuItems::eMenuItem_HighScores)
		{


		}
	
	}

	else if(m_nMenuState == MenuStates::eMenu_Game)
	{
		
		ChangeMenuState(MenuStates::eMenu_Main); //start the game! Woot!
		pMenu->Enable();
	}

	return m_nMenuState;
}


//deinit crap
StateManager::~StateManager()
{


}